package com.tangcco.lockwell.service.impl;

import com.tangcco.lockwell.domain.DataDictionary;
import com.tangcco.lockwell.domain.User;
import com.tangcco.lockwell.repository.BaseMapper;
import com.tangcco.lockwell.repository.DataDictionaryMapper;
import com.tangcco.lockwell.service.AuthenticationService;
import com.tangcco.lockwell.service.DataDictionaryService;
import com.tangcco.lockwell.viewmodel.admin.dataDictionary.DataDictionaryVM;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static com.tangcco.lockwell.utility.DateToString.dateToString;

/**
 * author：宋鑫垚
 * **/
@Service
public class DataDictionaryServiceImpl extends BaseServiceImpl<DataDictionary> implements DataDictionaryService {

    @Resource
    private final DataDictionaryMapper dataDictionaryMapper;

    public DataDictionaryServiceImpl(DataDictionaryMapper dataDictionaryMapper) {
        super(dataDictionaryMapper);
        this.dataDictionaryMapper = dataDictionaryMapper;
    }


    //按照分类编码进行查询
    @Override
    public List<DataDictionary> selectDataDictionaryByCategoryCode(String categoryCode) {
        return dataDictionaryMapper.selectDataDictionaryByCategoryCode(categoryCode);
    }

    //数据字典的灵活查询  不分页的那种 暂时还没用到
    @Override
    public List<DataDictionary> dataDictionarySelective(DataDictionary dataDictionary) {
        return dataDictionaryMapper.dataDictionarySelective(dataDictionary);
    }

    //数据字典 灵活 分页查询
    @Override
    public List<DataDictionaryVM> selectDataDictionaryByPage(DataDictionaryVM dataDictionaryVM) {
        return dataDictionaryMapper.selectDataDictionaryByPage(dataDictionaryVM);
    }

    //增加
    @Override
    public int insert(DataDictionary record) {
        record.setCreateTime(dateToString(new Date()));
        return super.insert(record);
    }

    //修改
    @Override
    public int updateById(DataDictionary record) {
        record.setModifyTime(dateToString(new Date()));
        return super.updateById(record);
    }

    //按照Id进行查询  详情查询
    @Override
    public DataDictionary selectById(Integer id) {
        return super.selectById(id);
    }

    //根据id 进行删除
    @Override
    public int deleteById(Integer id) {
        return super.deleteById(id);
    }

    /**
     * 查询学生端科目列表
     * @param dataDictionary
     * @return
     */
    @Override
    public List<DataDictionary> findMenuTreeByCondition(DataDictionary dataDictionary) {
        return dataDictionaryMapper.findMenuTreeByCondition(dataDictionary);
    }

    /**
     * 查询 学生端科目列表
     * @return
     */
    @Override
    public List<DataDictionary> findFistMenuForSubject() {
        return dataDictionaryMapper.findFistMenuForSubject();
    }

    @Override
    public List<DataDictionary> selectAllCode() {
        return dataDictionaryMapper.selectAllCode() ;
    }

    @Override
    public DataDictionary selectDataDictionaryById(int id) {
        return dataDictionaryMapper.selectByPrimaryKey(id);
    }
}
